<template>
  <n-form
    :model="formData"
    :rules="formRules"
    ref="formInstance"
    label-placement="left"
    label-width="80px">
    <n-grid x-gap="12" :cols="2" responsive="self">
            <n-gi >
        <n-form-item label="权限对象名称" path="securityObjName">
          <n-input clearable v-model:value="formData.securityObjName" placeholder="请输入权限对象名称" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="权限对象实体名称" path="securityObjEntityName">
          <n-input clearable v-model:value="formData.securityObjEntityName" placeholder="请输入权限对象实体名称" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="权限对象表名称" path="securityObjTableName">
          <n-input clearable v-model:value="formData.securityObjTableName" placeholder="请输入权限对象表名称" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="所属app" path="resourceAppCode">
          <n-input clearable v-model:value="formData.resourceAppCode" placeholder="请输入所属app" />
        </n-form-item>
      </n-gi>
          </n-grid>
  </n-form>
</template>
<script lang="ts">
import { onMounted, ref } from "vue";
import { enabledOptions, formRules } from "./Service";
import httpApi from "./httpApi";
import { FormInst } from "naive-ui";
import { checkFormData } from "slash-admin";

export default {
  props: {
    id: {
      type: [String, Number],
      default: null
    },
    readMode: {
      type: [String],
      default: "read"
    }
  },
  setup: function(props) {
    const formInstance = ref<FormInst | null>(null);
    const formData = ref<any>({
      id: props.id,
      enabled: 1
    });
    const init = async () => {
      if (props.id) {
        let msg = await httpApi.selectById(props.id);
        formData.value = msg.data;
      }
    };
    const doSubmit = async () => {
      await checkFormData(formInstance);
      return httpApi.doSaveEntity(formData.value);
    };
    const doUpdate = async () => {
      await checkFormData(formInstance);
      return httpApi.doUpdateEntity(formData.value);
    };
    onMounted(() => {
      init();
    });
    return {
      enabledOptions,
      formData,
      formInstance,
      formRules,
      doSubmit,
      doUpdate
    };
  }
};
</script>

<style lang="less" scoped></style>
